<?php
/** .-------------------------------------------------------------------
 * |  Software: [HDCMS framework]
 * |      Site: www.hdcms.com
 * |-------------------------------------------------------------------
 * |    Author: 向军 <2300071698@qq.com>
 * |    WeChat: aihoudun
 * | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
 * '-------------------------------------------------------------------*/

namespace web\admin\controller;


class Tag extends Common{
    protected $db;
	public function __construct()
	{
		parent::__construct();
		$this->db = new \system\model\Tag();
	}
//	载入模板
	public function index(){
		//调用模型中方法完成
		$data = $this->db->getAll();
//		加载模板
		View::with('data',$data)->make();
	}
//	添加
	public function add(){
		if (IS_POST){
			if ($this->db->store()){

				message('添加成功',u('index'),'success');
			}
			
			message($this->db->getError(),'','error');
		}
		View::make();
	}
//	编辑
	public function edit(){
		if (IS_POST){
			if ($this->db->edit()){
				message('编辑成功',u('index'),'success');
			}

			message($this->db->getError(),'','error');
		}
		$tid = q('get.tid',0,'intval');
		//获取旧数据
		$oldData = $this->db->where('tid',$tid)->first();
		View::with('oldData',$oldData)->make();
	}
//	删除
	public function del(){
		$tid = q('get.tid',0,'intval');
		$this->db->where('tid',$tid)->delete();
		message('删除成功',u('index'),'success');
	}
}

